package jee.boot.entity.auth;

import jee.boot.common.annotation.Column;
import jee.boot.common.annotation.FkTable;
import jee.boot.common.annotation.Table;
import jee.boot.common.basic.interceptor.impl.DefaultPreInsertInterceptor;
import jee.boot.common.basic.interceptor.impl.DefaultPreQueryInterceptor;
import jee.boot.common.basic.interceptor.impl.DefaultPreUpdateInterceptor;
import jee.boot.entity.system.BasicObj;
import jee.boot.entity.system.Operator;

/**
 * 记录集
 */
@Table(name = "mt_rowset_item")
public class RowSetItem extends BasicObj<RowSetItem> {

    private static final long serialVersionUID = 1L;
    /**
     * 头ID
     */
    @Column(name = "st_header_id", data = {"header.id", "header.no", "header.code", "header.name", "header.desc", "header.type"})
    private RowSet header;//引用：MT_ROWSET
    /**
     * 维度ID
     */
    @Column(name = "st_dim_id", data = {"dim.id", "dim.no", "dim.code", "dim.name", "dim.desc", "dim.type","dim.columnName","dim.dataDomainType","dim.dataDomain","dim.dataDomainFk"})
    private jee.boot.entity.auth.Column dim = new jee.boot.entity.auth.Column();//引用：MT_COLUMN(只引用其中ST_COLUMN_TYPE='DIC_MT_ColumnType_CT01'的数据)
    /**
     * 运算符ID
     */
    @Column(name = "st_operator_id", data = {"operator.id", "operator.no", "operator.code", "operator.name", "operator.desc", "operator.type", "operator.techName", "operator.keyword", "operator.rightValueType"})
    private Operator operator = new Operator();//引用：ST_OPERATOR
    /**
     * 表达式
     */
    @Column(name = "st_formula")
    private String formula;//文本，此处支持通配符、函数引用
    /**
     * 排序字段
     */
    private Integer sort = 0;
    @Column(
            action = Column.Action.QUERY,
            fkTable = {
                    @FkTable(alias = "dim", columnName = "st_model_id",
                            queryColumns = {"id", "modelTableName", "tableAlias"},
                            queryFields = {"dim.modelData.id", "dim.modelData.modelTableName", "dim.modelData.tableAlias"})
            }
    )
    private ModelData dimModel;//dim对应的模型

    public RowSetItem() {
    }

    public RowSetItem(String id) {
        super(id);
    }

    public RowSetItem(jee.boot.entity.auth.Column dim, Operator operator, String formula) {
        this.dim = dim;
        this.operator = operator;
        this.formula = formula;
    }

    public RowSet getHeader() {
        return header;
    }

    public void setHeader(RowSet header) {
        this.header = header;
    }

    public jee.boot.entity.auth.Column getDim() {
        return dim;
    }

    public void setDim(jee.boot.entity.auth.Column dim) {
        this.dim = dim;
    }

    public Operator getOperator() {
        return operator;
    }

    public void setOperator(Operator operator) {
        this.operator = operator;
    }

    public String getFormula() {
        return formula;
    }

    public void setFormula(String formula) {
        this.formula = formula;
    }

    public ModelData getDimModel() {
        return dimModel;
    }

    public void setDimModel(ModelData dimModel) {
        this.dimModel = dimModel;
    }

    public Integer getSort() {
        return sort;
    }

    public void setSort(Integer sort) {
        this.sort = sort;
    }
    @Override
    public void preInsert() {
        new DefaultPreInsertInterceptor().execute(this);
    }
    @Override
    public void preUpdate() {
        new DefaultPreUpdateInterceptor().execute(this);
    }
    @Override
    public void preQuery() {
        new DefaultPreQueryInterceptor().execute(this);
    }
}
